package com.share.servlet;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

public class demo6_redirect extends HttpServlet {

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

        System.out.println("demo6-threadName: " + Thread.currentThread().getName());
        resp.setContentType("text/html;charset=utf-8");
        //重定向，方式一
//        resp.setStatus(302);
//        resp.setHeader("location", "/sunxj-httpServletResponse/encoding");
        //重定向，方式二
        resp.sendRedirect("/sunxj-httpServletResponse/encoding");
        System.out.println("demo6-finish");

    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        super.doPost(req, resp);
    }
}
